using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Project_9_License_Barna
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            //Close the application
            this.Close();
        }


        //----------------Global Variables-----------------------------------------------------------
        StreamReader inputFile = File.OpenText("Answers.txt");
        StreamReader inputStudent = File.OpenText("Student.txt");
        List<string> AnswerList = new List<string>();
        List<string> StudentList = new List<string>();


        //Method to read correct answers file
        private void ReadCorrect_Answers()
        {
            //Open the correct answer file
            //StreamReader inputFile = File.OpenText("Answers.txt");
            
            //Clear the list box
            //lstIncorrectArray.Items.Clear();

            //Read the scores into the list
            while (!inputFile.EndOfStream)
            {
                AnswerList.Add(inputFile.ReadLine());
            }

            //Close the file
            //inputFile.Close();

            //foreach (string value in AnswerList)
            //{
            //    lstIncorrectArray.Items.Add(value);
            //}
        }

        //Method to read student answers file
        private void ReadStudent_Answers()
        {
            //Open the student answer file
            //StreamReader inputStudent = File.OpenText("Student.txt");

            //Read the student answers into the list
            while (!inputStudent.EndOfStream)
            {
                StudentList.Add(inputStudent.ReadLine());
            }

            //Close the file

            //inputStudent.Close();
        }
        
        //Method to find amount of correct answers
        private void Correct_Answers()
        {
            //Variables
            int index = 0;

            foreach (string value in AnswerList)
                {
                    lstIncorrectArray.Items.Add(value);
                }
            
                //for (correct = 0; correct < AnswerList.Count; index++)
                //foreach (string value in AnswerList)
                while (index < AnswerList.Count)
                {
                    index = 2;
                    if (AnswerList[index] != StudentList[index])  // This is the line that comes up with a run time error when I click the Check button 
                    {											  // on the application (btnCheck), ArgumentOutOfRangeException
                        index ++;
                        lblCorrect.Text = index.ToString();
                    }
                }
            

            
        }

        //Check button method
        private void btnCheck_Click(object sender, EventArgs e)
        {

            ReadCorrect_Answers();
            Correct_Answers();
        }
    }
}
